<?php

class Category extends Controller {
	
	function Category()
	{
		parent::Controller();
		$this->load->model('Category_model');	
		$this->lang->load('global_admin','english');
			
	}
	
	function index() {
		$data['inc_script'] = '';
		$data['category_info'] = $this->Category_model->getCategories();
		$this->load->view('administrator/category_view',$data);
	}	
	
	function add()
	{
		//get value from form
		$category_info = array(
			'name' => $this->input->post('tf_name'),
		);
		
		$form_validation = array(
			array('field' => 'tf_name','label' => 'lang:district_name','rules' => 'required|max_length[45]'),
		);
		$this->form_validation->set_rules($form_validation);

		if ($this->form_validation->run() == true) {
			$this->Category_model->addCategory($category_info);
			redirect('administrator/category');			
		}
		
		$data['inc_script'] = '';
		$this->load->view('administrator/category_add_view', $data);
	}
	
	function edit()
	{
		//get District id from uri
		$id = $this->uri->segment(4);
		
		//get value from form
		$category_info = array(
			'name' => $this->input->post('tf_name'),
		);
		
		$form_validation = array(
			array('field' => 'tf_name','label' => 'lang:district_name','rules' => 'required|max_length[45]'),
		);
		$this->form_validation->set_rules($form_validation);

		if ($this->form_validation->run() == true) {
			$this->Category_model->updateCategory($id,$category_info);
			redirect('administrator/category');			
		}
		
		$data['form_info'] = $this->Category_model->getCategory(array('id'=>$id));
		$data['inc_script'] = '';
		$this->load->view('administrator/category_edit_view', $data);
	}
	
	function delete()
	{
		$id = $this->uri->segment(4);	
		$this->Category_model->deleteCategory($id);
		redirect('administrator/category');		
	}
}